package com.webank.controller;

import com.webank.bean.Block;
import com.webank.bean.Car;
import com.webank.bean.Record;
import com.webank.service.ChainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/blockchain/getblocks")
public class ReadBlockController {

    @Autowired
    private ChainService chainService;

    @RequestMapping(value = "/{vin}", method = RequestMethod.GET)
    public List<Record> getBlocks(@PathVariable String vin) throws Exception{
        Car car = new Car();
        car.setVIN(vin);
        List<Record> resultBeanList = chainService.getRecords(car);
        return resultBeanList;
    }
}
